﻿<%@ Page Language="C#" AutoEventWireup="true" Inherits="DeliverGoodsManagement_ScanDelivery" Codebehind="ScanDelivery.aspx.cs" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>无标题页</title>
    <script type="text/jscript" language="javascript">
    window.onload=function winLoad()
	{
		document.getElementById("txtOrder").focus();	
	}
document.onkeydown = KeyAccess;
function KeyAccess(e)
{//debugger;
    if (document.all)
    {
        var ieKey=event.keyCode;
        var src=event.srcElement;
        var objOrder=document.getElementById("txtOrder");
        var objSPTM=document.getElementById("txtSPTM");
        if(ieKey==13||ieKey==108)
        {
           if(src==objOrder)
          {
               if(src.value.length>0)
               {
                   var arg="Order|"+src.value;
                   <%= ClientScript.GetCallbackEventReference(this, "arg", "ReceiveServerData", "")%>; 
                }
        
                document.getElementById("txtSPTM").focus();
           }
           if(src==objSPTM)
           {//debugger;
               var obj=document.getElementById("grdOrderDetail");
               var flag=0;//标识是否有条码扫错

               
               if(obj.all("code")==null) return;
               var rowCount=obj.rows.length;
               for(i=1;i<=rowCount;i++)
               {
                  var iTr=obj.rows[i];
                  if(iTr==null) continue;
                  if(obj.all("code",i-1)!=null)
                  {
                    var pos = i-1;
                    if(obj.all("tm",pos).innerText==objSPTM.value)
                    {   
                        flag=1;
                        
                        var qty=parseInt(obj.all("qty",pos).innerText,10);
                        var sqty=parseInt(obj.all("sqty",pos).innerText,10)+1;
                        if(qty>=sqty)
                        {
                            obj.all("sqty",pos).innerText=sqty;
                        }
                        else
                        {
                            alert("扫描数量不能大于订单商品数量"); return;
                        }
                    }
                  }
               }
               if(flag==0)
               {
                    alert("错误的商品条码"); return;
               }
               objSPTM.value="";
           }
           event.returnvalue=false;
        }
        
    }
}

function Check()
{debugger;
    
    var objOrder=document.getElementById("txtOrder");
    var objWLDH=document.getElementById("txtTraner");
    var arg="";
    if(objWLDH.value.length<=4)
    {
        alert("物流单号不允许少于4个字符长度"); return;
    }
    if(objWLDH!=null)
    {
        arg="Check|"+objOrder.value+"|"+objWLDH.value;
        <%= ClientScript.GetCallbackEventReference(this, "arg", "AlertData", "")%>; 
    }
}
function AlertData(result)
{debugger;
    if(result!="") 
    {
        var arr=result.split("|");
        
        if(arr[0].length>0) alert(arr[0]);
    }
    else
    {
        document.getElementById("btnSend").style.display="inline";
        alert("检查通过");
    }
}
function Send()
{debugger;

    var objOrder=document.getElementById("txtOrder");
    var objSPTM=document.getElementById("txtSPTM");
    var objWLDH=document.getElementById("txtTraner");
    var arg="";
    var flag=0;//标识扫描数量和订单商品数量是否有差异
    var obj=document.getElementById("grdOrderDetail");
    if(obj.all("code")==null) return;
    var rowCount=obj.rows.length;
    for(i=1;i<=rowCount;i++)
     {
         var iTr=obj.rows[i];
         if(iTr==null) continue;
         if(obj.all("code",i-1)!=null)
         {
             var pos = i-1;
             var code=obj.all("code",pos).innerText;
             var mc=obj.all("mc",pos).innerText;
             var color=obj.all("color",pos).innerText;
             var size=obj.all("size",pos).innerText;
             var qty=parseInt(obj.all("qty",pos).innerText,10);
             var sqty=parseInt(obj.all("sqty",pos).innerText,10);
             var tm=obj.all("tm",pos).innerText;
             var id=obj.all("id",pos).innerText;
             arg=arg+code+","+mc+","+color+","+size+","+qty+","+sqty+","+tm+","+id+";";
   
             if(qty!=sqty)
             {
                 flag=1;
             }
         }
     }
     if(flag==1)
     {debugger;
        if(confirm("是否生成差异订单？"))
        {//第四个参数表识是否生成差异订单        
            arg="Send,"+objOrder.value+","+objWLDH.value+",1|"+arg;
        }
        else
        {//修改原订单

            arg="Send,"+objOrder.value+","+objWLDH.value+",0|"+arg;
        }
        <%= ClientScript.GetCallbackEventReference(this, "arg", "ReceiveServerData", "")%>; 
     }
     else
     {
        arg="Send,"+objOrder.value+","+objWLDH.value+",0|"+arg;
        <%= ClientScript.GetCallbackEventReference(this, "arg", "ReceiveServerData", "")%>; 
     }
     
}
function ReceiveServerData(result)  
{//debugger;
    arr=result.split("|");
    if(arr[0]!="")
    {
        if(arr[1]=="Order")
        {
            document.getElementById("grd").innerHTML=arr[0];
        }
        if(arr[1]=="Send")
        {
            document.getElementById("btnSend").style.display="none";
            alert(arr[0]);
        }
    }
}
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <div>
        订单编号：<input type="text" id="txtOrder" />
        商品条码：<input type="text" id="txtSPTM" />
        物流单号：<input type="text" id="txtTraner"/>
        <input type="button" id="btnCheck" value="出库检查" onclick="javascript:Check()" />
        <input type="button" id="btnSend" value="出库"  style="display:none" onclick="javascript:Send()" />
        <input type="button" id="btnClose" value="关闭" onclick="javascript:window.opener=null;window.close()" />
        </div>
        <div id="grd"></div>
        <asp:GridView ID="grdOrderDetail" runat="server" AutoGenerateColumns="False" Width="100%">
            <Columns>
                <asp:BoundField HeaderText="订单编号" DataField="OD_ID" />
                <asp:BoundField HeaderText="商品代码" DataField="OD_CMDCODE" />
                <asp:BoundField HeaderText="商品名称" DataField="SPMC" />
                <asp:BoundField DataField="OD_COLORCODE" HeaderText="颜色代码" />
                <asp:BoundField HeaderText="颜色" DataField="COLORNAME" />
                <asp:BoundField DataField="OD_SIZECODE" HeaderText="尺码代码" />
                <asp:BoundField HeaderText="尺码" DataField="SIZENAME" />
                <asp:BoundField HeaderText="数量" DataField="OD_QTY" />
                <asp:BoundField HeaderText="扫描数量" DataField="SCANQTY" />
                <asp:BoundField HeaderText="商品条码" DataField="SPTM" />
            </Columns>
        </asp:GridView>
    </div>
    </form>
</body>
</html>
